package edu.cuit.avatar.inherit;

/**
 * @author <a href="mailto:1020zhaodan@163.com">Adan</a>
 * @version 1.0
 * @date 2025/7/9 15:04
 */
public class PetTest {
    public static void main(String[] args) {
        //创建狗狗宠物
        Pet dannie = new Dog();
        dannie.setName("小狗Dannie");
        //dannie.setStrain("拉布拉多犬");
        System.out.println(dannie.sayHello());

        //创建企鹅宠物
        Pet penguin = new Penguin();
        penguin.setName("瑞格");
        //penguin.setGender("Male");
        System.out.println(penguin.sayHello());

        //创建猪猪宠物
        Pet peppa = new Pig(); //多态
        peppa.setName("小猪Peppa");
        System.out.println(peppa.sayHello());
        //printPetInfo(peppa);
        System.out.println(peppa); //peppa.toString()===>从Object而来



        Pet[] pets = {dannie, peppa, penguin};
        for(var pet : pets)
            printPetInfo(pet);
    }

    //多态
    public static void printPetInfo(Pet pet){
        System.out.println(pet.sayHello());
    }
}
